
/*
num.sort((a,b)=>a-b);
console.log(num);
var arr = ['B', 'C', 'A'];
arr.sort();
console.log(arr);
*/

// var num = [345, 45, 65, 25, 55];
// num.so = function () {
//     var a;
//     for (var j = 0; j < this.length-1; j++) {
//         for (var i = j+1; i < this.length; i++) {
//             if (this[i] < this[j]) {
//                 a = this[j];
//                 this[j] = this[i];
//                 this[i] = a;
//             }
//         }
//     }
//     console.log(num);
// }
// num.so();



var num = [345, 45, 65, 25, 55];
num.so = function (fn) {
    var a;
    for (var j = 0; j < this.length-1; j++) {
        for (var i = j+1; i < this.length; i++) {
            if (fn(this[i],this[j])) {
                a = this[j];
                this[j] = this[i];
                this[i] = a;
            }
        }
    }
    console.log(num);
}
num.so(function(a,b){return a>b});//a>b大到小
 //输出[345, 65, 55, 45, 25, so: ƒ]
num.so(function(a,b){return a<b});
 //输出[25, 45, 55, 65, 345, so: ƒ]
num.so(function(a,b){return a-b});//大->小
num.so(function(a,b){return a+b});//小->大
